<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 select-info">
            <form id="city_master_list_form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list">
                    <ul>
                        <li>
                            城市名称：<input type="text" name="name"/>
                        </li>
                        <li>
                            省市区聚合：<input type="text" name="mergerName"/>
                        </li>
                        <li>
                            级别：<select name="levelType" th:with="type=${@dict.getType('city_lv_type')}">
                            <option value="">所有</option>
                            <option th:each="e : ${type}" th:text="${e['dictLabel']}" th:value="${e['dictValue']}"></option>
                        </select>
                        </li>
                        <li class="time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            开启状态：<select name="cityStatus" >
                            <option value="">所有</option>
                            <option value="1">开启</option>
                            <option value="0">未开启</option>
                        </select>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.exportExcel()"
                               shiro:hasPermission="system:user:export"><i class="fa fa-download"></i>&nbsp;导出</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="btn-group hidden-xs" id="toolbar" role="group">
            <a class="btn btn-outline btn-success btn-rounded" onclick="openCity()"  shiro:hasPermission="city:cityMasterList:add">
                <i class="fa fa-plus"></i>城市开启
            </a>
        </div>

        <div class="col-sm-12 select-info table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('city:cityMasterList:edit')}]];
    var removeFlag = [[${@permission.hasPermi('city:cityMasterList:remove')}]];
    var cityMasterStatusDatas = [[${@dict.getType('city_master_status')}]];
    var prefix = ctx + "city/cityMasterList"

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "主城",
            limit:50,
            sortName : "lastPrice",
            sortOrder : "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'adCode',
                    title: '城市编号'
                },
                {
                    field: 'levelType',
                    title: '级别',
                    formatter: function(value, row, index) {

                        if(1 == value){
                            return "省";
                        }else if (2 == value) {
                            return "市";
                        }else if (3 == value){
                            return "区";
                        }else{
                            return "未知";
                        }
                        return value;
                    }
                },
                {
                    field: 'mergerName',
                    title: '名称'
                },
                {
                    field: 'nickName',
                    title: '所属用户'
                },
                {
                    field: 'userd',
                    title: '用户id',
                    formatter: function(value, row, index) {
                        var value="";
                        var userId = row.userId;
                        if(userId && userId.indexOf("123456789") != -1){
                            value = userId;
                        }else{
                            value = "---";
                        }
                        return value;
                    }
                },
                {
                    field: 'lastPrice',
                    title: '最后交易价格'
                },
                {
                    field: 'lastTransactionTime',
                    title: '最后交易时间'
                },
                {
                    field: 'newBuyPrice',
                    title: '最新购买价格'
                },
                {
                    field: 'cityStatus',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if(row.levelType == 1){
                            return "--"
                        }else{
                            return $.table.selectDictLabel(cityMasterStatusDatas, value);
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.adCode + '\')"><i class="fa fa-edit"></i>明细</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="beforeBuyCity(\'' + row.adCode + '\')"><i class="fa fa-edit"></i>购买</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });



    //购买界面
    function beforeBuyCity(id){

        var beforeBuyCityUrl = prefix + "/beforeBuyCity/{id}";

        var url = beforeBuyCityUrl.replace("{id}", id);
        $.modal.open("购买城市", url);

    }


    //判断是不是特殊账号
    function checkOurUser(value){
        console.log(value);
            return "--";

        // if(value.indexOf("1234567890") != -1){
        //     return value;
        // }else{
        // }
    }


    // 批量开城操作
    function openCity() {
        var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要要开放选中的" + rows.length + "个城市吗吗?", function() {
            var url = $.table._option.removeUrl;
            var data = { "ids": rows.join() };


            $.modal.loading("正在处理中，请稍后...");
            var config = {
                timeout: 30000,
                url: prefix + "/openCity",
                type: "post",
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        layer.msg(result.msg, {
                            icon: $.modal.icon(modal_status.SUCCESS),
                            time: 1000,
                            shade: [0.1, '#8F8F8F']
                        });
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();

                },
                error: function (data, status, xhr) {
                    layer.msg(data, {
                        icon: $.modal.icon(modal_status.FAIL),
                        time: 1000,
                        shade: [0.1, '#8F8F8F']
                    });
                }
            };
            $.ajax(config)

        });
    }


</script>
</body>
</html>